<?php 
require_once("../includes/config.php");
  if (($_SESSION["r"]>0&&$_SESSION["admin"]!=1)&&!isset($_SESSION['admin_id']))
  {
  	$_SESSION['error_message'] = "غير مسموح";
	redirect("index.php");
	die();
  }
  
    $result= query("SELECT * FROM apartments_owner WHERE user_id=?",$_GET['id']);
     
    if(empty($result))
    {
      $_SESSION["error_message"] = "حدث خطأ";
       redirect("index.php");
    }  
    else
    {
      $row = $result[0];
	  if (!isset($_SESSION["admin_id"]))
	  {
	  $_SESSION["admin_id"]=$_SESSION["id"];
	  }
	  elseif($_SESSION["admin_id"]==$row["user_id"])
	  {
	  unset($_SESSION["admin_id"]);
	  }


      $_SESSION["login_user"] = $row["first_name"]. " ".$row["last_name"] ; 
      $_SESSION["user_id"] = $row["id"];
	  $_SESSION["id"]=$row["user_id"];
      $_SESSION["organization"] = $row["orgnanization_name"] ; 
      $_SESSION["phone"] = $row["phone"] ; 
      $_SESSION["place"] = $row["place"] ; 
      $_SESSION["success"]= "Welcome " .$_SESSION["login_user"] ;
	  $_SESSION["r"]=$row["role"];
	  if ($_SESSION["r"]<2)
	  {
	  $_SESSION["logo"]=$row["logo"];
	  }
	  else
	  {
	  $resultz= query("SELECT * FROM apartments_owner WHERE user_id=?",$row["id"]);
	  $rowz=$resultz[0];
	  $_SESSION["logo"]=$rowz["logo"];
	  }
	  if ($_SESSION["r"]==3)
	  {
	  redirect("reports.php");
	  }
	  else
	  {
      redirect("index.php");
	  }
    }  

?>